package command;

import model.EnhancedCostEvaluator;
import model.Solution;

public class MoveProcessToMachineCommand implements Command {

	EnhancedCostEvaluator costEvaluator;
	Solution new_solution;
	int p_id;
	int m_id;
	int old_m_id = -1;

	public MoveProcessToMachineCommand(EnhancedCostEvaluator ce) {
		this.costEvaluator = ce;
		this.new_solution = costEvaluator.getNewSolution();
	}

	public int getP_id() {
		return p_id;
	}

	public void setP_id(int p_id) {
		this.p_id = p_id;
	}

	public int getM_id() {
		return m_id;
	}

	public void setM_id(int m_id) {
		this.m_id = m_id;
	}

	@Override
	public void execute() {
		old_m_id = new_solution.getMachineIdForProcessId(p_id);
		new_solution.removeProcess(p_id);
//		System.out.printf("assign p%d to m%d which was in m%d\n", p_id, m_id,
//				old_m_id);
		new_solution.assignProcessToMachine(p_id, m_id);
	}

	@Override
	public void undo() {
		new_solution.removeProcess(p_id);
//		System.out.printf("assign p%d to m%d\n", p_id, old_m_id);
		new_solution.assignProcessToMachine(p_id, old_m_id);
		old_m_id = -1;
	}

	@Override
	public String toString() {
		return "MoveProcessToMachineCommand [m_id=" + m_id + ", old_m_id=" + old_m_id + ", p_id=" + p_id + "]";
	}

}
